//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;

namespace OpenLS.Chart
{
    internal delegate void ResolverAction(Axis a);

    internal class AxisResolver
    {
        private readonly List<KeyValuePair<uint, ResolverAction>> _actions =
            new List<KeyValuePair<uint, ResolverAction>>();

        private readonly Dictionary<uint, Axis> _axesTable = new Dictionary<uint, Axis>();

        public void AddAxis(Axis a)
        {
            _axesTable.Add(a.Id, a);
        }

        public void AddAction(uint id, ResolverAction action)
        {
            if (id == 0)
            {
                action(null);
                return;
            }
            _actions.Add(new KeyValuePair<uint, ResolverAction>(id, action));
        }

        public void AddAction(uint? id, ResolverAction action)
        {
            if (id == null)
            {
                action(null);
                return;
            }
            AddAction(id.Value, action);
        }

        internal void Resolve()
        {
            foreach (KeyValuePair<uint, ResolverAction> p in _actions)
            {
                p.Value(_axesTable[p.Key]);
            }
        }
    }
}